using ChangingValidationFromAndbyAggregate.Dominio;
using NHibernate.Validator.Cfg.Loquacious;

namespace ChangingValidationFromAndbyAggregate.Validators
{
    public class OrderValidation : ValidationDef<Order>
    {
        public OrderValidation()
        {
            ValidateInstance.By((order, validationContext) =>
                                    {
                                        if (order.Customer != null)
                                        {
                                            return true;
                                        }
                                        else
                                        {
                                            validationContext.AddInvalid<Order, string>("Customer uninformed.", p => p.Customer.ToString());
                                            return true;
                                        }
                                    });

            Define(x => x.Customer).IsValid();
        }
    }
}